﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using DGSFramework;

namespace Framework.Resources
{
    public partial class Watermark : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadWatermark();
            }
        }

        public void LoadWatermark()
        {
            XDocument xDocWatermark = XDocument.Load(Server.MapPath(ConfigPaths.Path_Watermark_Xml));
            XElement xEImage = xDocWatermark.Descendants("img").FirstOrDefault();
            XElement xEEnable = xDocWatermark.Descendants("enable").FirstOrDefault();
            if (xEImage.Value.Trim() != "")
            {
                chkWartermark.Visible = true;
                if (xEEnable.Value.Trim() == "0")
                {
                    chkWartermark.Checked = false;
                }
                else
                {
                    chkWartermark.Checked = true;
                }
            }
            else
            {
                chkWartermark.Visible = false;
            }
        }

        protected void chkWartermark_CheckedChanged(object sender, EventArgs e)
        {
            XDocument xDocWatermark = XDocument.Load(Server.MapPath(ConfigPaths.Path_Watermark_Xml));
            XElement xEEnable = xDocWatermark.Descendants("enable").FirstOrDefault();

            if (chkWartermark.Checked == true)
            {
                xEEnable.Value = "1";
            }
            else
            {
                xEEnable.Value = "0";
            }
            xDocWatermark.Save(Server.MapPath(ConfigPaths.Path_Watermark_Xml));
            LoadWatermark();
        }
    }
}